package com.liehacker.android.etcs;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.liehacker.android.R;
import com.liehacker.android.util.AESCrypto;

public class SecurityActivity extends Activity{
	
	Button _btnEncrypt;
	Button _btnDecrypt;
	EditText _edtText;
	TextView _txtView;
	AESCrypto _aesCrypto = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.c03_edittext);
		
		_aesCrypto = new AESCrypto();
		_edtText = (EditText)findViewById(R.id.c03_edittext);
		_txtView = (TextView)findViewById(R.id.c03_result_text);
		
		_btnEncrypt = (Button)findViewById(R.id.c03_encrypt_button);		
		_btnEncrypt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					SecurityActivity.this.AesEncrpt();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		});
		
		_btnDecrypt = (Button)findViewById(R.id.c03_decrypt_button);
		_btnDecrypt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					SecurityActivity.this.AesDecrpt();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		});
	}
	
	public void AesEncrpt() throws Exception {		
		String strResult = "";
		strResult = _aesCrypto.encryptAES(_edtText.getText().toString());
		_txtView.setText(strResult);
		
	}
	
	public void AesDecrpt() throws Exception {
		String strResult = "";
		strResult = _aesCrypto.decryptAES(_txtView.getText().toString());
		_txtView.setText(strResult);
	}
}
